package io.renren.modules.avanotes.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.vo.input.StudyScheduleIUVo;
import io.renren.common.vo.output.StudyScheduleOVo;
import io.renren.modules.avanotes.entity.FormworkEntity;
import io.renren.modules.avanotes.entity.StudyScheduleEntity;
import io.renren.modules.avanotes.service.StudyScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 学习计划表
 *
 * @author zzr
 * @email 529742454@qq.com
 * @date 2022-02-19 14:47:32
 */
@RestController
@RequestMapping("avanotes/studyschedule")
@Api("学习计划表接口")
public class StudyScheduleController {

    @Autowired
    private StudyScheduleService studyScheduleService;

    //region 自定义业务

    /**
     *
     * @param name
     * @return
     */
    @PostMapping("/list4select/{name}")
    @ApiOperation("模糊搜索 计划名称")
    public R list4select( @PathVariable("name") String name) {
        List<StudyScheduleEntity> list = studyScheduleService.list4SelectByName(name);

        //return R.ok().put("page", page);
        return R.ok().setData(list);
    }

    //listSituation
    @PostMapping("/listSituation")
    //@RequiresPermissions("avanotes:studyschedule:list")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "limit", value = "每页记录数", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "key", value = "检索关键字", paramType = "query", dataType = "String")
    //})
    @ApiOperation("查询任务完成情况列表（绑定个人）")
    public R listSituation(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = studyScheduleService.listSituationQueryPage(params);

        //return R.ok().put("page", page);
        return R.ok().setData(page);
    }


    @PostMapping("/insert")
    //@RequiresPermissions("avanotes:studyschedule:save")
    @ApiOperation("保存")
    public R insert(@RequestBody StudyScheduleIUVo vo) throws Exception {
        long id = studyScheduleService.insert(vo);
        return R.ok().setData(id);
    }

    /**
     * 查询单条详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("查询单条详情")
    public R detail(@PathVariable("id") Long id) {
        StudyScheduleOVo studySchedule = studyScheduleService.getEntityDetailById(id);

        //return R.ok().put("studySchedule", studySchedule);
        return R.ok().setData(studySchedule);
    }

    //endregion

    /**
     * 列表
     */
    @PostMapping("/list")
    //@RequiresPermissions("avanotes:studyschedule:list")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "limit", value = "每页记录数", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "key", value = "检索关键字", paramType = "query", dataType = "String")
    //})
    //@ApiOperation("查询列表")
    public R list(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = studyScheduleService.queryPage(params);

        //return R.ok().put("page", page);
        return R.ok().setData(page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("avanotes:studyschedule:info")
    @ApiOperation("查询单条")
    public R info(@PathVariable("id") Long id) {
        StudyScheduleEntity studySchedule = studyScheduleService.getById(id);

        //return R.ok().put("studySchedule", studySchedule);
        return R.ok().setData(studySchedule);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("avanotes:studyschedule:save")
    @ApiOperation("保存")
    public R save(@RequestBody StudyScheduleEntity studySchedule) {
        studyScheduleService.save(studySchedule);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("avanotes:studyschedule:update")
    //@ApiOperation("修改")
    public R update(@RequestBody StudyScheduleEntity studySchedule) {
        studyScheduleService.updateById(studySchedule);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("avanotes:studyschedule:delete")
    //@ApiOperation("删除")
    public R delete(@RequestBody Long[] ids) {
        studyScheduleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
